<template>
  <a-modal
    :title="title"
    :after-close="reset"
    @ok="submit"
  >
    <a-form
      ref="formRef"
      :model="form"
      :rules="rules"
      :label-col="{style: { width: '80px' }}"
    >
                                                        <a-form-item label="城市id" name="cityId">
                    <a-input  v-model:value="form.cityId" placeholder="城市id"></a-input>
                </a-form-item>
                                                <a-form-item label="省市级别" name="level">
                    <a-input  v-model:value="form.level" placeholder="省市级别"></a-input>
                </a-form-item>
                                                <a-form-item label="父级id" name="parentId">
                    <a-input  v-model:value="form.parentId" placeholder="父级id"></a-input>
                </a-form-item>
                                                <a-form-item label="区号" name="areaCode">
                    <a-input  v-model:value="form.areaCode" placeholder="区号"></a-input>
                </a-form-item>
                                                <a-form-item label="名称" name="name">
                    <a-input  v-model:value="form.name" placeholder="名称"></a-input>
                </a-form-item>
                                                <a-form-item label="合并名称" name="mergerName">
                    <a-input  v-model:value="form.mergerName" placeholder="合并名称"></a-input>
                </a-form-item>
                                                <a-form-item label="经度" name="lng">
                    <a-input  v-model:value="form.lng" placeholder="经度"></a-input>
                </a-form-item>
                                                <a-form-item label="纬度" name="lat">
                    <a-input  v-model:value="form.lat" placeholder="纬度"></a-input>
                </a-form-item>
                                                <a-form-item label="是否展示" name="isShow">
                    <a-input  v-model:value="form.isShow" placeholder="是否展示"></a-input>
                </a-form-item>
                                                <a-form-item label="创建时间" name="createTime">
                    <a-input  v-model:value="form.createTime" placeholder="创建时间"></a-input>
                </a-form-item>
                                                <a-form-item label="更新时间" name="updateTime">
                    <a-input  v-model:value="form.updateTime" placeholder="更新时间"></a-input>
                </a-form-item>
                        </a-form>
  </a-modal>
</template>

<script setup lang="ts">
import { systemcityAddup, systemcityinfo } from './api';
import { systemcity, type Isystemcity } from './entity';
import { validReg } from '@/utils/validate';

const props = withDefaults(defineProps<{
  data: Partial<Isystemcity>
}>(),{
})
const title = computed(() => props.data.id ? '编辑' : '新增')
const { formRef, submit, close } = useDialog({ validCallback: save })

let form = $ref(new systemcity())
watchEffect(() => {
  if (props.data.id) {
    systemcityinfo(props.data.id).then(res => {
      form.setProps(res)
    })
  }
})

const rules = {
        systemcityName: [validReg('required', '请输入用户名')]
}

onMounted(() => {
})
const emit = defineEmits(['change'])
function save() {
    systemcityAddup(form).then(() => {
    AntMessage.success('保存成功')
    close()
    emit('change')
  })
}

function reset() {
  form = new systemcity()
}
</script>

<style lang="less"></style>